﻿using System;
using System.Collections.Generic;
using System.Text;
using LBoL.Base;
using LBoL.Base.Extensions;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.EntityLib.Cards.Character.Marisa;
using LBoL.EntityLib.Cards.Neutral.Blue;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeGatewaySupportDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Skill;
            config.Rarity = Rarity.Common;

            config.Colors = new List<ManaColor>() { ManaColor.White };
            config.Cost = new ManaGroup() { White = 1 };

            config.IsXCost = true;

            config.RelativeCards = new List<string>() { "ProbeZealotCharge", "ProbeStalker" };
            config.UpgradedRelativeCards = new List<string>() { "ProbeZealotCharge", "ProbeStalker" };

            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }
    }

    /// <summary>
    /// 传送门支援
    /// WX
    /// 将1个狂热者洗入弃牌堆
    /// 每支付x：将一个狂热者洗入弃牌堆
    /// 每支付2：将追猎者置入手牌/和一个狂热者洗入弃牌堆
    /// </summary>
    [EntityLogic(typeof(ProbeGatewaySupportDef))]
    public sealed class ProbeGatewaySupport : ProbeCard
    {
        // 获取X费
        public override ManaGroup GetXCostFromPooled(ManaGroup pooledMana)
        {
            return pooledMana;
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            //  洗狂热者
            yield return new AddCardsToDiscardAction(Library.CreateCards<ProbeZealotCharge>(1));

            var mana = base.PendingManaUsage.GetValueOrDefault();
            var zealotCount = IsUpgraded? SynergyAmount(mana, ManaColor.Any)/2+ SynergyAmount(mana, ManaColor.Any):SynergyAmount(mana, ManaColor.Any);
            var stalkerCount = SynergyAmount(mana, ManaColor.Any)/2;

            yield return new AddCardsToDiscardAction(Library.CreateCards<ProbeZealotCharge>(zealotCount));
            yield return new AddCardsToHandAction(Library.CreateCards<ProbeStalker>(stalkerCount));
        }
    }
}
